package com.ruoyi.project.system.introduction.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.introduction.domain.Introduction;
import com.ruoyi.project.system.introduction.service.IIntroductionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 说明Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/introduction")
public class IntroductionController extends BaseController
{
    private String prefix = "system/introduction";

    @Autowired
    private IIntroductionService introductionService;

    @RequiresPermissions("system:introduction:view")
    @GetMapping()
    public String introduction()
    {
        return prefix + "/introduction";
    }

    /**
     * 查询说明列表
     */
    @RequiresPermissions("system:introduction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Introduction introduction)
    {
        startPage();
        List<Introduction> list = introductionService.selectIntroductionList(introduction);
        return getDataTable(list);
    }

    /**
     * 导出说明列表
     */
    @RequiresPermissions("system:introduction:export")
    @Log(title = "说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Introduction introduction)
    {
        List<Introduction> list = introductionService.selectIntroductionList(introduction);
        ExcelUtil<Introduction> util = new ExcelUtil<Introduction>(Introduction.class);
        return util.exportExcel(list, "说明数据");
    }

    /**
     * 新增说明
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存说明
     */
    @RequiresPermissions("system:introduction:add")
    @Log(title = "说明", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Introduction introduction)
    {
        return toAjax(introductionService.insertIntroduction(introduction));
    }

    /**
     * 修改说明
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Introduction introduction = introductionService.selectIntroductionById(id);
        mmap.put("introduction", introduction);
        return prefix + "/edit";
    }

    /**
     * 修改保存说明
     */
    @RequiresPermissions("system:introduction:edit")
    @Log(title = "说明", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Introduction introduction)
    {
        return toAjax(introductionService.updateIntroduction(introduction));
    }

    /**
     * 删除说明
     */
    @RequiresPermissions("system:introduction:remove")
    @Log(title = "说明", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(introductionService.deleteIntroductionByIds(ids));
    }
}
